'''
作者:袁俊
描述:将订单列表页面封装为一个类
'''
# 引入模块
from MY_ECShop.common.base import Base, create_browser,create_loading_browser
from MY_ECShop.page.Menu import PageMenu
import time


# 创建订单列表类
class PageOrderList(Base):
    # 类属性
    order_sn = ('name', 'order_sn') # 订单号输入框
    consignee = ('name', 'consignee')   # 收货人输入框
    order_status = ('name', 'status')   # 订单状态输入框
    search_submit = ('css selector','input[type="submit"]')     # 搜索框
    advanced_search_submit = ('class name', "btn-search cl-link")   # 高级搜索框
    search_result = ('id', 'order_0')  # 表中第一条数据订单号
    checkboxes = ('xpath', '/html/body/form/div/table[1]/tbody/tr[3]/td[1]/input')
    remove_button = ('name', 'remove')  # 移除按钮
    # 封装方法
    # 输入订单号
    def page_orderlist_input_ordersn(self, ordersn):
        self.base_input_massage(self.order_sn, ordersn)

    # 输入收件人
    def page_orderlist_input_consignee(self, consignee):
        self.base_input_massage(self.consignee, consignee)

    # 选择订单状态
    def page_orderlist_choose_status(self, text):     # 3 默认未发货
        self.base_drop_down_menu_by_text(self.order_status, text)


    # 点击搜索按钮
    def page_orderlist_click_search(self):
        self.base_click(self.search_submit)

    # 获取订单号用于断言
    def page_orderlist_get_ordersn(self):
        return self.base_get_text(self.search_result)

    # 点击订单选择框
    def page_orderlist_order_checkbox(self):
        self.base_click(self.checkboxes)

    # 点击移除按钮
    def page_orderlist_click_remove(self):
        self.base_click(self.remove_button)

    # 退出浏览器
    def page_orderlist_quit_web(self):
        self.base_quit_web()

if __name__ == '__main__':
    my_browser = create_loading_browser('yuan_jun')  # 创建配置项浏览器
    pagemenu_object = PageMenu(my_browser)  # 创建菜单页面对象
    pagemenu_object.page_menu_background_open()  # 打开后台端
    pagemenu_object.page_menu_into_menu_iframe()  # 进入menu-frame
    pagemenu_object.page_menu_click_ordermanage()  # 点击订单管理按钮
    pagemenu_object.page_menu_click_orderlist()  # 点击订单列表按钮
    pagemenu_object.page_menu_quit_iframe()  # 退出menu-frame
    pagemenu_object.page_menu_into_main_iframe()  # 进入main-frame
    pageorderlist_object = PageOrderList(my_browser)  # 创建订单列表页面对象
    pageorderlist_object.page_orderlist_order_checkbox()
    pageorderlist_object.page_orderlist_click_remove()